<?php header("Content-Type:text/html;   charset=utf-8"); ?>
<script type="text/javascript">
	$(function(){
		loadUser();
		$("#btnQuery").bind("click",loadUser);	
		
		$("#hrefDelUserManage").bind("click",delSelect);
		$("#hrefStartUserManage").bind("click",startSelect);
		$("#hrefStopUserManage").bind("click",stopSelect);
			
	});
 	function delSelect(){
 	 	var selIds=getSelectIds();
 	 	if(selIds==""){
 	 	 	alert('请选择要删除的项');
 	 	 	return;
 	 	}
 	 	if(confirm('删除后不可恢复，确认要删除吗？')==false)
 	 	 	return;
 	 	var params={uid:selIds};
 	 	var url="index.php/UserManage/del";
 	 	$.ajax({
 	 	 	type:"post",
 	 	 	url:url,
 	 	 	dataType:"json",
 	 	 	data:params,
 	 	 	success:function(data){
				if(data.ReturnCode=="1"){
					loadUser();
					alert('删除成功');
				}else{
					alert('删除失败');
				}
 	 	 	}
 	 	});
 	}
 	function startSelect(){
 	 	var selIds=getSelectIds();
 	 	if(selIds==""){
 	 	 	alert('请选择要启用的项');
 	 	 	return;
 	 	} 	 	
 	 	var params ={uid:selIds};
 	 	var url="index.php/UserManage/startUser"; 	 	
 	 	$.ajax({
 	 	 	type:"post",
 	 	 	url:url,
 	 	 	dataType:"json",
 	 	 	data:params,
 	 	 	success:function(data){ 	 	 	 	
 	 	 	 	if(data.ReturnCode=="1"){
 	 	 	 	 	loadUser();
 	 	 	 	 	alert('启用成功');
 	 	 	 	}else{
 	 	 	 	 	alert('启用失败');
 	 	 	 	}
 	 	 	}
 	 	});
 	}
	function stopSelect(){
		var selIds = getSelectIds();
		if(selIds==""){
			alert('请选择要停用的项');
			return;
		}
		var params = {uid:selIds};
		var url="index.php/UserManage/stopUser";
		$.ajax({
			type:"post",
			url:url,
			dataType:"json",
			data:params,
			success:function(data){
				if(data.ReturnCode=="1"){
					loadUser();
					alert('停用成功');
				}else{
					alert('停用失败');
				}
			}
		});
	}
	function getSelectIds(){
		var sel = "";
		$("#tableUserManage td :checkbox:checked").each(function(){
			sel+=$(this).val()+",";
		});
		return sel;
	}
	function loadUser(){
		$("#chkSelectAllUserManage").attr("checked",false);
		var params={
					username:$("#txtUserName").val(),
					roleid:$("#selRole").val(),
					status:$("#selStatus").val()
				};
		var url="index.php/UserManage/loadUser";
		$.ajax({
			type:"post",
			url:url,
			dataType:"html",
			data:params,
			success:function(data){				
				$("#tableUserManage").html(data);
				bindSelect("chkSelectAllUserManage","tableUserManage");				
			}
		});	
	}
	function modify(id){		
		$("#hrefEditUserManage").attr("href","index.php/UserManage/add?uid="+id);
		$("#hrefEditUserManage").trigger("click");
	}
	function del(id){
		if(confirm('删除后不可恢复，确定要继续删除吗？')){
			var params = {uid:id};
			var url="index.php/UserManage/del";
			$.ajax({
				type:"post",
				url:url,
				dataType:"json",
				data:params,
				success:function(data){
					if(data.ReturnCode=="1"){
						loadUser();
						alert('删除成功');
					}else{
						alert('删除失败');
					}
				}
			});
		}
	}
</script>

<div class="pageHeader">
	<form onsubmit="return navTabSearch(this);" action="demo_page1.html"
		method="post">
		<div class="searchBar">
			<table class="searchContent">
				<tr>
					<td>用户名：<input type="text" id="txtUserName" name="txtUserName" />
					</td>
					<td>角色：<select id="selRole" name="selRole" style="width: 120px">
							<option value=''>请选择角色...</option>
					<?php
					
					foreach ( $listRole as $key => $value ) {
						print "<option value='$key'>$value</option>";
					}
					?>
					</select></td>
					<td>有效状态：<select id="selStatus" name="selStatus"
						style="width: 160px">
							<option value=''>请选择账号状态...</option>
							<option value="1">启用</option>
							<option value="2">停用</option>
					</select></td>
					<td>
						<div class="subBar">
							<ul>
								<li><div class="buttonActive">
										<div class="buttonContent">
											<button id="btnQuery" type="button" style="width: 100px">查&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;询</button>
										</div>
									</div></li>
							</ul>
						</div>
					</td>
				</tr>
			</table>

		</div>
	</form>
</div>
<div class="pageContent">
	<div class="panelBar">
		<ul class="toolBar">
			<li><a class="add" href="index.php/UserManage/add"
				lookupgroup="orgLookup"><span>添加新用户</span></a></li>
			<li style="display: none"><a id="hrefEditUserManage" class="edit"
				href="" lookupgroup="orgLookup"><span>修改</span></a></li>
			<li><a id="hrefDelUserManage" class="delete"
				href="javascript:void(0)"><span>删除</span></a></li>
			<li><a id="hrefStartUserManage" class="edit"
				href="javascript:void(0)"><span>启用</span></a></li>
			<li><a id="hrefStopUserManage" class="icon" href="javascript:void(0)"><span>停用</span></a></li>
		</ul>
	</div>
	<table class="table" width="100%" layoutH="138">
		<thead>
			<tr>
				<th style='width: 30px;text-align:center;'><input type='checkbox'
					id='chkSelectAllUserManage' /></th>
				<th style='width: 120px'>用户名</th>
				<th style='width: 120px'>密码</th>
				<th style='width: 120px'>中文名</th>
				<th style='width: 120px'>用户ID</th>
				<th style='width: 120px'>角色</th>
				<th style='width: 100px'>状态</th>
				<th style='width: 200px'>操作</th>
			</tr>
		</thead>
		<tbody id="tableUserManage">

		</tbody>
	</table>
</div>

